"""# 谜题训练场开发任务

## 任务概述
你是一位资深程序员，我需要你帮我实现一个特定谜题的训练场环境类。这个类继承自`Basebootcamp`，用于生成谜题实例并验证解答。

## 背景说明
我正在开发一系列谜题训练场，每个训练场对应一个特定类型的谜题。训练场类命名为`{PuzzleName}bootcamp`，其中`PuzzleName`是谜题的名称。

每个训练场类主要提供两个核心功能：
1. 生成该谜题类型的问题实例
2. 验证用户对问题的回答是否正确

## 技术接口规范

### 类方法实现要求

```python
from bootcamp import Basebootcamp

class {PuzzleName}bootcamp(Basebootcamp):
    def __init__(self, **params):
        \"\"\"
        请你自定义params，以保存该puzzle相关的参数，例如网格大小等，参数配有默认值
        \"\"\"
        pass
    
    def case_generator(self):
        \"\"\"
        生成谜题实例，提示：为保证谜题有解，可以先生成结果再对结果处理得到谜题
        返回：一个可JSON序列化的字典（避免包含set等无法通过json.dumps处理的数据结构）
        \"\"\"
        pass
    
    @staticmethod
    def prompt_func(question_case) -> str:
        \"\"\"
        将case_generator生成的谜题实例转换为文本形式的问题，问题中包含问题背景、对谜题规则的介绍、具体要解决的谜题实例、期望最终答案的格式，
        例如：你是xxxx，请你解答yyyy，规则如下：yyyy，最终答案放置在：zzzzz
        注意：请参照提供的谜题描述进行复述，规则应当描述详细，包括任务背景、具体任务操作规则、对题目格式和答案格式的含义介绍等，

        参数:
            question_case: 由case_generator生成的谜题实例
            
        返回:
            str: 格式化的问题字符串
            
        注意:
            1. 需考虑问题的格式，以便后续能正确提取
            2. 问题描述中应包含期望的答案格式说明，以便后续能正确提取，为了避免抽取时匹配出干扰项，请要求模型将答案放在特定标签（如双括号）内，例如[[your answer here]]
        \"\"\"
        pass
    
    @staticmethod
    def extract_output(output):
        \"\"\"
        从LLM的回复中提取符合格式要求的答案，如有多个，请抽取最后一个，避免使用re.search等只抽取第一个结果的方式。
        
        参数:
            output: LLM的完整输出（包含原始问题和回答）
            
        返回:
            提取的答案，若未找到符合格式的答案则返回None
        \"\"\"
        pass
    
    @classmethod
    def _verify_correction(cls, solution, identity):
        \"\"\"
        验证提取的答案是否正确，注意一个问题可以能有多个解，按照谜题规则进行检验，不要直接匹配可能的答案。
        
        参数:
            solution: extract_output提取的答案
            identity: case_generator生成的谜题实例
            
        返回:
            bool: 答案是否正确
        \"\"\"
        pass
```

### 验证评分方法（基类已实现）

```python
@classmethod
def verify_score(cls, model_output, identity:dict, format_score=0.1) -> float:
    \"\"\"
    验证输出结果并评分。
    
    参数:
        model_output: 模型的完整输出
        identity: 谜题实例（由case_generator生成）
        format_score: 答案格式正确时的基础分数
    
    返回:
        float: 评分结果（0-1之间）
    \"\"\"
    score = 0. 
    try:
        extract_solution = cls.extract_output(model_output)
        if extract_solution is None:
            return score
        else:
            score = format_score # 格式正确时的基础分数
        if cls._verify_correction(extract_solution, identity):
            score = 1.  # 答案完全正确时的满分
    except Exception as e:
        # 处理异常情况
        pass
    return score
```

### 使用示例

```python
# 初始化谜题训练场
bootcamp = Puzzlebootcamp()

# 生成谜题实例
case = bootcamp.case_generator()

# 将谜题转换为文本问题
prompt = Puzzlebootcamp.prompt_func(case)

# 获取LLM对问题的解答
response = get_response(prompt, \"LLM\")

# 从完整对话中提取答案
extracted_output = Puzzlebootcamp.extract_output(prompt + response)

# 验证答案并评分
score = Puzzlebootcamp.verify_score(extracted_output, case)
```

## 你的任务
请根据以下谜题描述（谜题描述可能不完整，请先结合你的知识澄清规则），实现一个完整的谜题训练场类：

### 谜题描述
**Encryption Rules:**

- Input:
    - Plaintext: Uppercase letters string without punctuation and spaces.
- Output:
    - Ciphertext: Uppercase letters string.
- Preparation:
    - standard_alphabet: \"ABCDEFGHIJKLMNOPQRSTUVWXYZ\"
    - reversed_alphabet: \"ZYXWVUTSRQPONMLKJIHGFEDCBA\"
    - substitution_alphabet: \"RFDJUHABCEGIKLMNOPQSTVWXYZ\"
- Encryption Steps:
    - For each letter p in the given Plaintext:
    - (1) Use reversed_alphabet for reverse mapping. Find its position in the standard_alphabet and replace it with the letter in the corresponding position in reversed_alphabet. For example, A is mapped to Z and B is mapped to Y.
    - (2) Move the letter obtained in (1) forward 4 places in the standard_alphabet order. For example, if p=A, after (1) is mapped to Z, then Z is shifted forward 4 positions in the standard_alphabet to get D.
    - (3) Replace the letter obtained from (2) by finding its position in standard_alphabet and using the corresponding letter in substitution_alphabet, resulting in the final ciphertext letter. For example, if the letter obtained by going through (2) is D, it is mapped as J.

**Decryption Rules:**

- Input:
    - Ciphertext: Uppercase letters string.
- Output:
    - Plaintext: Uppercase letters string.
- Preparation:
    - alphabet: \"ABCDEFGHIJKLMNOPQRSTUVWXYZ\"
    - reversed_alphabet: \"ZYXWVUTSRQPONMLKJIHGFEDCBA\"
    - substitution_alphabet: \"RFDJUHABCEGIKLMNOPQSTVWXYZ\"
- Decryption Steps (exact opposite of encryption steps):
    - (1) For each letter c in Ciphertext, find its position in substitution_alphabet and replace it with the corresponding letter in standard_alphabet.
    - (2) Shift the letter obtained from (1) backward by 4 positions according to the standard_alphabet order.
    - (3) Replace the letter obtained from (2) by finding its position in reversed_alphabet, then replace it with the corresponding letter in standard_alphabet. For example, Z maps to A, Y maps to B.

Reference implementation of this cipher is as follows
```python{\"idx\": \"2\", \"title\": \"Custom Pigpen / Masonic Cipher\", \"rule_content\": \"**Encryption Rules:**\n\n- Input:\n    - Plaintext: Uppercase letters string without punctuation and spaces.\n- Output:\n    - Ciphertext: Uppercase letters string.\n- Preparation:\n    - encryption_table = {\n    'A': '!', 'B': '@', 'C': '#', 'D': '$',\n    'E': '%', 'F': '^', 'G': '&', 'H': '*',\n    'I': '(', 'J': ')', 'K': '_', 'L': '+',\n    'M': '=', 'N': '~', 'O': '?', 'P': '/',\n    'Q': '0', 'R': ':', 'S': ';', 'T': '<',\n    'U': '>', 'V': '1', 'W': '2', 'X': '3',\n    'Y': '4', 'Z': '5'\n    }\n- Encryption Steps:\n    - For each given plaintext character p:\n        - If `p` is an uppercase letter and exists in the encryption table:\n            - Replace `p` with the corresponding symbol from the encryption table.\n\n **Decryption Rules:**\n\n- Input:\n    - Ciphertext: Uppercase letters string.\n- Output:\n    - Plaintext: Uppercase letters string.\n- Preparation:\n    - encryption_table = {\n    'A': '!', 'B': '@', 'C': '#', 'D': '$',\n    'E': '%', 'F': '^', 'G': '&', 'H': '*',\n    'I': '(', 'J': ')', 'K': '_', 'L': '+',\n    'M': '=', 'N': '~', 'O': '?', 'P': '/',\n    'Q': '0', 'R': ':', 'S': ';', 'T': '<',\n    'U': '>', 'V': '1', 'W': '2', 'X': '3',\n    'Y': '4', 'Z': '5'\n    }\n- Decryption Steps (exact opposite of encryption steps):\n    - For each given ciphertext character c:\n        - If `c` is a symbol from the encryption table and exists in the encryption table:\n            - Replace `c` with the corresponding uppercase letter from the encryption table.\", \"tag\": \"Classical Cryptography,Monoalphabetic Ciphers\"}
{\"idx\": \"3\", \"title\": \"Custom Multi-tap Phone Code\", \"rule_content\": \"**Encryption Rules:**\n\n- Input:\n    - Plaintext: Uppercase letters string without punctuation and spaces.\n- Output:\n    - Ciphertext: A string without punctuation.\n- Preparation:\n    - Multitap Code Table\n        | Letter | Multitap Code |\n        | --- | --- |\n        | A | 2^1 |\n        | B | 2^2 |\n        | C | 2^3 |\n        | D | 3^1 |\n        | E | 3^2 |\n        | F | 3^3 |\n        | G | 4^1 |\n        | H | 4^2 |\n        | I | 4^3 |\n        | J | 5^1 |\n        | K | 5^2 |\n        | L | 5^3 |\n        | M | 6^1 |\n        | N | 6^2 |\n        | O | 6^3 |\n        | P | 7^1 |\n        | Q | 7^2 |\n        | R | 7^3 |\n        | S | 7^4 |\n        | T | 8^1 |\n        | U | 8^2 |\n        | V | 8^3 |\n        | W | 9^1 |\n        | X | 9^2 |\n        | Y | 9^3 |\n        | Z | 9^4 |\n- Encryption Steps:\n    - For each given plaintext character p:\n        - If `p` is an uppercase letter and exists in the Multitap Code Table:\n            - Replace `p` with the corresponding Multitap Code from the Multitap Code Table.\n\n **Decryption Rules:**\n\n- Input:\n    - Ciphertext: A string without punctuation.\n- Output:\n    - Plaintext: Uppercase letters string.\n- Preparation: Multitap Code Table (Same as encryption)\n- Decryption Steps (exact opposite of encryption steps):\n    - For each given ciphertext Multitap Code c:\n        - If `c` is a Multitap Code from the Multitap Code Table:\n            - Replace `c` with the corresponding uppercase letter from the Multitap Code Table.\", \"tag\": \"Classical Cryptography,Monoalphabetic Ciphers\"}
{\"idx\": \"4\", \"title\": \"Custom Polybius Square Cipher\", \"rule_content\": \"**Encryption Rules:**\n\n- Input:\n    - Plaintext: Uppercase letters string without punctuation and spaces.\n- Output:\n    - Ciphertext: Uppercase letters string.\n- Preparation:\n    - Polybius_square:\n```\n+----+----+----+----+----+\n|    | 1  | 2  | 3  | 4  | 5  |\n+----+----+----+----+----+\n| 1  | R  | T  | X  | F  | S  |\n| 2  | W  | C  | M  | V  | H  |\n| 3  | Z  | J  | A  | P  | B  |\n| 4  | L  | Q  | Y  | G  | K  |\n| 5  | N  | E  | U  | D  | I  |\n+----+----+----+----+----+\n```\n- Encryption Steps:\n    - For each given plaintext character p:\n        - If `p` is an uppercase letter and exists in the Polybius square:\n            - Replace `p` with the number of rows and columns (both counted from 1) in which the character appears.\n        - In particular, O, which does not exist in the Polybius square, is replaced by 66.\n\n **Decryption Rules:**\n\n- Input:\n    - Ciphertext: A string.\n- Output:\n    - Plaintext: Uppercase letters string.\n- Preparation: Polybius_square (Same as encryption)\n- Decryption Steps (exact opposite of encryption steps):\n    - For each of the two numbers CrCc in the given ciphertext.\n        - Based on the rows and columns denoted by CrCc, find the corresponding letters in the Polybius square grid.\n        - If CrCc=66, replace with \\"O\\".\", \"tag\": \"Classical Cryptography,Monoalphabetic Ciphers\"}
{\"idx\": \"5\", \"title\": \"Custom Affine Cipher\", \"rule_content\": \"**Encryption Rules:**\n\n- Input:\n    - Plaintext: Uppercase letters string without punctuation and spaces.\n- Output:\n    - Ciphertext: Uppercase letters string.\n- Preparation:\n    - affine alphabet = \\"XMJQUDONPRGTVBWFAKSHZCYEIL\\"\n    - Associate each letter with its position in the affine alphabet (starting from 0):\n        \n        X -> 0, M -> 1, J -> 2, Q -> 3, U -> 4, D -> 5, O -> 6, N -> 7,\n        P -> 8, R -> 9, G -> 10, T -> 11, V -> 12, B -> 13, W -> 14, F -> 15,\n        A -> 16, K -> 17, S -> 18, H -> 19, Z -> 20, C -> 21, Y -> 22, E -> 23, I -> 24, L -> 25\n        \n    - A: 3\n    - B: 5\n    - A_inv: 9\n- Encryption Steps:\n    - For each given plaintext character p:\n        - Let  x  denote its position in the affine alphabet.\n        - Apply the affine coding function to compute y:\n            - y = (Ax + B) mod 26\n        - Find the corresponding letter in the affine alphabet at position  y , forming the encrypted message.\n\n **Decryption Rules:**\n\n- Input:\n    - Ciphertext: Uppercase letters string.\n- Output:\n    - Plaintext: Uppercase letters string.\n- Preparation:\n    - affine alphabet = \\"XMJQUDONPRGTVBWFAKSHZCYEIL\\"\n    - Associate each letter with its position in the affine alphabet (starting from 0):\n        \n        X -> 0, M -> 1, J -> 2, Q -> 3, U -> 4, D -> 5, O -> 6, N -> 7,\n        P -> 8, R -> 9, G -> 10, T -> 11, V -> 12, B -> 13, W -> 14, F -> 15,\n        A -> 16, K -> 17, S -> 18, H -> 19, Z -> 20, C -> 21, Y -> 22, E -> 23, I -> 24, L -> 25\n        \n    - A: 3\n    - B: 5\n    - A_inv: 9\n- Decryption Steps (exact opposite of encryption steps):\n    - For each given ciphertext character c:\n        - Let y denote its position in the affine alphabet.\n        - Calculate x:\n            - x = A_inv * (y - B) % n.\n        - Replace c with the letter at position x  in the affine alphabet to form the decrypted message.\", \"tag\": \"Classical Cryptography,Monoalphabetic Ciphers\"}
{\"idx\": \"6\", \"title\": \"Custom Solitaire Cipher\", \"rule_content\": \"**Encryption Rules:**\n\n- Input:\n    - Plaintext: Uppercase letters string without punctuation and spaces.\n- Output:\n    - Ciphertext: Uppercase letters string.\n- Preparation:\n    - LETTERS = ['J', 'D', 'W', 'O', 'T', 'R', 'A', 'C', 'X', 'Q', 'M', 'F', 'Y',\n    'E', 'Z', 'G', 'U', 'K', 'P', 'V', 'B', 'S', 'H', 'N', 'L', 'I']\n    - Associate each letter with its position in the LETTERS (starting from 0):\n        \n        J -> 0, D -> 1, W -> 2, O -> 3, T -> 4, R -> 5, A -> 6, C -> 7, X -> 8, Q -> 9,\n        M -> 10, F -> 11, Y -> 12, E -> 13, Z -> 14, G -> 15, U -> 16, K -> 17, P -> 18,\n        V -> 19, B -> 20, S -> 21, H -> 22, N -> 23, L -> 24, I -> 25\n        \n    - Initial sequence of cards:\n        - A list of 54 numbers, including a randomly shuffled deck consisting of 52 suited cards and two distinguishable jokers known as the A Joker and B Joker. Suited cards are valued sequentially across four suits: Clubs, Diamonds, Hearts, and Spades, with values ranging from 1 to 52, while the jokers are valued 53 and 54.\n        - [9, 25, 44, 38, 40, 22, 11, 36, 13, 39, 18, 42, 10, 53, 26, 12, 1, 16, 3, 43, 37, 17, 30, 4, 28, 48, 27, 41, 32, 15, 47, 29, 20, 51, 6, 7, 52, 34, 35, 5, 50, 9, 54, 46, 23, 31, 24, 14, 8, 33, 2, 49, 45, 21]\n    - **Keystream Algorithm**\n        \n        This algorithm generates keystream values by moving cards within a deck. The keystream algorithm is *deterministic*, meaning keystream values depend solely on the initial order of the deck. The deck is treated as a circular array, allowing a card that needs to move below the bottom card to wrap around to the top (in other words, the first card follows the last card).\n        \n        For example, starting with:\n        9, 25, 44, 38, 40, 22, 11, 36, 13, 39, 18, 42, 10, 53, 26, 12, 1, 16, 3, 43, 37, 17, 30, 4, 28, 48, 27, 41, 32, 15, 47, 29, 20, 51, 6, 7, 52, 34, 35, 5, 50, 9, 54, 46, 23, 31, 24, 14, 8, 33, 2, 49, 45, 21\n        \n        Perform the following steps to generate a character of the keystream:\n        \n        1. Locate card A and move it down by one position. If it's the last card, it becomes the second card. It cannot become the first card. The deck now looks like this:\n        9, 25, 44, 38, 40, 22, 11, 36, 13, 39, 18, 42, 10, 26, **53,** 12, 1, 16, 3, 43, 37, 17, 30, 4, 28, 48, 27, 41, 32, 15, 47, 29, 20, 51, 6, 7, 52, 34, 35, 5, 50, 9, 54, 46, 23, 31, 24, 14, 8, 33, 2, 49, 45, 21\n        2. Locate card B and move it down by two positions. Note, if it's the second last card, it will wrap around to become the second card. If it's the last card, it will become the third card. It cannot become the first card. The deck now looks like this:\n        9, 25, 44, 38, 40, 22, 11, 36, 13, 39, 18, 42, 10, 26, **53,** 12, 1, 16, 3, 43, 37, 17, 30, 4, 28, 48, 27, 41, 32, 15, 47, 29, 20, 51, 6, 7, 52, 34, 35, 5, 50, 9, 46, 23, **54,** 31, 24, 14, 8, 33, 2, 49, 45, 21\n        3. Perform a \\"triple cut\\": Divide the deck into three parts, using the jokers as boundaries, then swap the top and bottom parts. The jokers themselves and the cards between them remain unchanged.\n        31, 24, 14, 8, 33, 2, 49, 45, 21, **53,** 12, 1, 16, 3, 43, 37, 17, 30, 4, 28, 48, 27, 41, 32, 15, 47, 29, 20, 51, 6, 7, 52, 34, 35, 5, 50, 9, 46, 23, **54,** 9, 25, 44, 38, 40, 22, 11, 36, 13, 39, 18, 42, 10, 26\n        4. Perform a \\"count cut\\": Examine the bottom card of the deck. If it's a joker (53/54), its value remains fixed at 53. Take out that many cards from the top of the deck and insert them just above the last card of the deck.\n        29, 20, 51, 6, 7, 52, 34, 35, 5, 50, 9, 46, 23, **54,** 9, 25, 44, 38, 40, 22, 11, 36, 13, 39, 18, 42, 10, **31, 24, 14, 8, 33, 2, 49, 45, 21,** 53, 12, 1, 16, 3, 43, 37, 17, 30, 4, 28, 48, 27, 41, 32, 15, 47, 26\n        5. Now, look at the value of the top card. Similarly, any joker counts as 53. Calculate the number of positions below this card, and use that card's value as the next value in the keystream. If the calculated card is a joker, ignore it and repeat the keystream algorithm. In this example, the top card is 29, so the value of the 30th card (i.e., 14) determines the keystream value. (Note that no cards change position in this step; this step only determines the keystream value).\n        6. Return the resulting keystream value: 14\n- Encryption Steps:\n    - cards=Initial sequence of cards\n    - For each given plaintext character p:\n        - Use the alphabet to convert p to the corresponding positional value x. (starting from 0).\n        - Generate a keystream value y for p using the Initial sequence of cards:\n            - y, cards = Keystream Algorithm (cards)\n            - This algorithm modifies the order of the pile of cards, and the next execution then uses the new order.\n        - When the keystream value y is added to the position value x, the mod 26 operation is applied to obtain z:\n            - z=(y+x) % 26\n        - Use the LETTERS list to return the letter corresponding to position z.\n        - Append it to the ciphertext.\n\n **Decryption Rules:**\n\n- Input:\n    - Ciphertext: Uppercase letters string.\n- Output:\n    - Plaintext: Uppercase letters string.\n- Preparation:\n    - LETTERS = ['J', 'D', 'W', 'O', 'T', 'R', 'A', 'C', 'X', 'Q', 'M', 'F', 'Y',\n    'E', 'Z', 'G', 'U', 'K', 'P', 'V', 'B', 'S', 'H', 'N', 'L', 'I']\n    - Associate each letter with its position in the LETTERS (starting from 0):\n        \n        J -> 0, D -> 1, W -> 2, O -> 3, T -> 4, R -> 5, A -> 6, C -> 7, X -> 8, Q -> 9,\n        M -> 10, F -> 11, Y -> 12, E -> 13, Z -> 14, G -> 15, U -> 16, K -> 17, P -> 18,\n        V -> 19, B -> 20, S -> 21, H -> 22, N -> 23, L -> 24, I -> 25\n        \n    - Initial sequence of cards(Same as encryption)\n    - Keystream Algorithm(Same as encryption)\n- Decryption Steps (exact opposite of encryption steps):\n    - cards=Initial sequence of cards\n    - For each ciphertext character c:\n        - Convert c to its corresponding positional value z using the LETTERS (starting from 0).\n        - Generate the keystream value y for c:\n            - y, cards = Keystream Algorithm (cards)\n            - This algorithm modifies the order of the pile of cards, and the next execution then uses the new order.\n        - Calculate the original positional value x from ciphertext character c:\n            - x=(z-y) mod 26\n        - Use the LETTERS list to return the letter corresponding to position x.\n        - Append it to the decrypted plaintext.\", \"tag\": \"Classical Cryptography,Polyalphabetic Ciphers\"}
{\"idx\": \"7\", \"title\": \"Custom Phillips Figure Cipher\", \"rule_content\": \"**Encryption Rules:**\n\n- Input:\n    - Plaintext: Uppercase letters string without punctuation and spaces.\n- Output:\n    - Ciphertext: Uppercase letters string.\n- Preparation:\n    - alphabet = 'ABCDEFGHIKLMNOPQRSTUVWXYZ'(The letter J is excluded)\n    - 8 Grids:\n        \n        Grid0:\n        \n        | P | H | I | L | S |\n        | A | B | C | D | E |\n        | F | G | K | M | N |\n        | O | Q | R | T | U |\n        | V | W | X | Y | Z |\n        \n        Grid1:\n        \n        | V | W | X | Y | Z |\n        | P | H | I | L | S |\n        | A | B | C | D | E |\n        | F | G | K | M | N |\n        | O | Q | R | T | U |\n        \n        Grid2:\n        \n        | O | Q | R | T | U |\n        | V | W | X | Y | Z |\n        | P | H | I | L | S |\n        | A | B | C | D | E |\n        | F | G | K | M | N |\n        \n        Grid3:\n        \n        | F | G | K | M | N |\n        | O | Q | R | T | U |\n        | V | W | X | Y | Z |\n        | P | H | I | L | S |\n        | A | B | C | D | E |\n        \n        Grid4:\n        \n        | A | B | C | D | E |\n        | F | G | K | M | N |\n        | O | Q | R | T | U |\n        | V | W | X | Y | Z |\n        | P | H | I | L | S |\n        \n        Grid5:\n        \n        | P | H | I | L | S |\n        | A | B | C | D | E |\n        | F | G | K | M | N |\n        | O | Q | R | T | U |\n        | V | W | X | Y | Z |\n        \n        Grid6:\n        \n        | V | W | X | Y | Z |\n        | P | H | I | L | S |\n        | A | B | C | D | E |\n        | F | G | K | M | N |\n        | O | Q | R | T | U |\n        \n        Grid7:\n        \n        | O | Q | R | T | U |\n        | V | W | X | Y | Z |\n        | P | H | I | L | S |\n        | A | B | C | D | E |\n        | F | G | K | M | N |\n        \n- Encryption Steps:\n    - The plaintext is grouped into blocks of 5 characters, numbered from 0.\n    - For blocks of 5 characters:\n        - To use the grid is determined by calculating grid_index = (i // 5) % 8, where i is the number. Integer division operator // divides the number on the left by the number on the right, rounding down the result. That is, it removes the fractional part and keeps only the integer part!This ensures that the grid is recycled.\n        - For each character in the current block:\n            - If the character is \\"J\\", it is not encrypted and is appended directly to the encrypted block.\n            - Otherwise, find the position of the character in the current grid. Then move one grid position to the lower right (row+1,col+1) (or continue on the opposite side of the corresponding boundary if it crosses the boundary), and get the letter at the position after the move as the encrypted letter.\n            - Add the encrypted letter to the encryption block.\n    - After processing all the blocks, connect the encrypted blocks to form the final encrypted message.\n\n **Decryption Rules:**\n\n- Input:\n    - Ciphertext: Uppercase letters string.\n- Output:\n    - Plaintext: Uppercase letters string.\n- Preparation:\n    - alphabet = 'ABCDEFGHIKLMNOPQRSTUVWXYZ'(The letter J is excluded)\n    - 8 Grids (Same as encryption)\n- Decryption Steps (exact opposite of encryption steps):\n    - Divide the ciphertext into 5-character blocks:\n        - For example, if the cipher text is \\"KHOORTQHQTHHSAUQ\\", the 0th block is \\"KHOOR\\", the 1st block is \\"TQHQH\\", and so on. (Numbering starts at 0)\n    - Determine the grid used for the current block:\n    Calculate grid_index = (i // 5) % 8 to select the appropriate grid from the grid list. i is the block number.\n    - For each character in the block:\n        - If the character is \\"J\\": add \\"J\\" directly to the decrypted block without decryption.\n        - Otherwise find the position of the character in the grid and obtain it by moving one grid to the upper left (or continue on the opposite side of the corresponding boundary if it crosses the boundary). the letter at the position after the move is used as the decrypted letter.\n        - Append the decrypted letter to the decryption block.\n    - After processing all characters in the block, append the decrypted block to the decrypted message list. Form the final decrypted message.\", \"tag\": \"Classical Cryptography,Polyalphabetic Ciphers\"}
{\"idx\": \"8\", \"title\": \"Custom Porta Cipher\", \"rule_content\": \"**Encryption Rules:**\n\n- Input:\n    - Plaintext: Uppercase letters string without punctuation and spaces.\n    - Key: The key is a string used to select the alphabets. Each letter in the key will be used to select the corresponding alphabet for encryption or decryption.\n- Output:\n    - Ciphertext: Uppercase letters string.\n- Preparation:\n    - Cipher Alphabets\n        \n        Use the following 13 cipher alphabets, each associated with two letters:\n        AB: NOPQRSTUVWXYZABCDEFGHIJKLM\n        CD: ZNOPQRSTUVWXYBCDEFGHIJKLMA\n        EF: YZNOPQRSTUVWXCDEFGHIJKLMAB\n        GH: XYZNOPQRSTUVWDEFGHIJKLMABC\n        IJ: WXYZNOPQRSTUVEFGHIJKLMABCD\n        KL: VWXYZNOPQRSTUFGHIJKLMABCDE\n        MN: UVWXYZNOPQRSTGHIJKLMABCDEF\n        OP: TUVWXYZNOPQRSHIJKLMABCDEFG\n        QR: STUVWXYZNOPQRIJKLMABCDEFGH\n        ST: RSTUVWXYZNOPQJKLMABCDEFGHI\n        UV: QRSTUVWXYZNOPKLMABCDEFGHIJ\n        WX: PQRSTUVWXYZNOLMABCDEFGHIJK\n        YZ: OPQRSTUVWXYZNMABCDEFGHIJKL\n        \n    - Standard Alphabet\n        - ABCDEFGHIJKLMNOPQRSTUVWXYZ\n- Encryption Steps:\n    - Pair each letter in the key with each letter in the plaintext. If the key is shorter than the plaintext, repeat the key.\n    - For each given plaintext character p:\n        - Find the corresponding cipher alphabet based on the key letter paired with it. If the key letter is A, mark the choice AB: NOPQRSTUVWXYZABCDEFGHIJKLM\n        - Find the position of p in the standard alphabet and replace it with the letter at the same position in the cipher alphabet.\n\n **Decryption Rules:**\n\n- Input:\n    - Ciphertext: Uppercase letters string.\n    - Key: The key is a string used to select the alphabets. Each letter in the key will be used to select the corresponding alphabet for encryption or decryption.\n- Output:\n    - Plaintext: Uppercase letters string.\n- Preparation:\n    - Cipher Alphabets (Same as encryption)\n    - Standard Alphabet(Same as encryption)\n- Decryption Steps (exact opposite of encryption steps):\n    - Pair each letter in the key with each letter in the ciphertext. If the key is shorter than the plaintext, repeat the key.\n    - For each given ciphertext character c:\n        - Find the corresponding cipher alphabet based on the key letter paired with it. If the key letter is A, mark AB Option: NOPQRSTUVWXYZABCDEFGHIJKLM\n        - Find the position of c in the cipher alphabet and reduce it to the plaintext letter using the same position in the standard alphabet.\", \"tag\": \"Classical Cryptography,Polyalphabetic Ciphers\"}
{\"idx\": \"9\", \"title\": \"Custom Alberti Cipher\", \"rule_content\": \"**Encryption Rules:**\n\n- Input:\n    - Plaintext: Uppercase letters string without punctuation and spaces.\n    - period: Defines how often the inner disc rotates. Periodicity indicates that after every number of characters processed in the encryption process, the inner disc will rotate once according to the incremental value.\n    - increment: Defines the number of characters the inner disc rotates each time. At the end of each cycle, the inner disc will rotate to the right by the corresponding number of characters based on the increment value. For example, if the increment is 4, the inner disc will rotate 4 characters to the right for each cycle that passes (e.g., 5 characters are processed).\n- Output:\n    - Ciphertext: Uppercase letters string.\n- Preparation:\n    - outer_disk = \\"QWERTYUIOPASDFGHJZXCVBNMKL\\"\n    - inner_disk = \\"JKLZXCVBNMASDFGHJQWERTYUIO\\"\n- Encryption Steps:\n    - For each character p in the plaintext:\n        - Find the character in the outer_disk.\n        - Replace it with the character at the corresponding position on the inner_disk.\n        - After encrypting every `period` characters, rotate the inner_disk to the right by `increment` characters.For example, rotating 'ZXCVBNMASDFGHJKLQWERTYUIOP' by 4 gives 'BNMASDFGHJKLQWERTYUIOPZXCV'.\n\n **Decryption Rules:**\n\n- Input:\n    - Ciphertext: Uppercase letters string.\n    - period (Same as encryption)\n    - increment (Same as encryption)\n- Output:\n    - Plaintext: Uppercase letters string.\n- Preparation:\n    - outer_disk = \\"QWERTYUIOPASDFGHJZXCVBNMKL\\"\n    - inner_disk = \\"JKLZXCVBNMASDFGHJQWERTYUIO\\"\n- Decryption Steps (exact opposite of encryption steps):\n    - For each character c in the ciphertext:\n        - Find the character in the inner_disk.\n        - Replace the character with the corresponding position in the outer_disk.\n        - After decrypting every `period` characters, rotate the inner_disk to the right by `increment` characters.For example, rotating 'ZXCVBNMASDFGHJKLQWERTYUIOP' by 4 gives 'BNMASDFGHJKLQWERTYUIOPZXCV'.\", \"tag\": \"Classical Cryptography,Polyalphabetic Ciphers\"}
{\"idx\": \"10\", \"title\": \"Custom Jefferson Cipher\", \"rule_content\": \"**Encryption Rules:**\n\n- Input:\n    - Plaintext: Uppercase letters string without punctuation and spaces.\n- Output:\n    - Ciphertext: Uppercase letters string.\n- Preparation:\n    - Reels\n        \n        Reel1:   \\"ABCEIGDJFVUYMHTQKZOLRXSPWN\\",\n        Reel2:   \\"ACDEHFIJKTLMOUVYGZNPQXRWSB\\",\n        Reel3:   \\"ADKOMJUBGEPHSCZINXFYQRTVWL\\",\n        Reel4:   \\"AEDCBIFGJHLKMRUOQVPTNWYXZS\\",\n        Reel5:   \\"AFNQUKDOPITJBRHCYSLWEMZVXG\\",\n        Reel6:   \\"AGPOCIXLURNDYZHWBJSQFKVMET\\",\n        Reel7:    \\"AHXJEZBNIKPVROGSYDULCFMQTW\\",\n        Reel8:    \\"AIHPJOBWKCVFZLQERYNSUMGTDX\\",\n        Reel9:    \\"AJDSKQOIVTZEFHGYUNLPMBXWCR\\",\n        Reel10:   \\"AKELBDFJGHONMTPRQSVZUXYWIC\\",\n        Reel11:    \\"ALTMSXVQPNOHUWDIZYCGKRFBEJ\\",\n        Reel12:    \\"AMNFLHQGCUJTBYPZKXISRDVEWO\\",\n        Reel13:    \\"ANCJILDHBMKGXUZTSWQYVORPFE\\",\n        Reel14:    \\"AODWPKJVIUQHZCTXBLEGNYRSMF\\",\n        Reel15:    \\"APBVHIYKSGUENTCXOWFQDRLJZM\\",\n        Reel16:    \\"AQJNUBTGIMWZRVLXCSHDEOKFPY\\",\n        Reel17:    \\"ARMYOFTHEUSZJXDPCWGQIBKLNV\\",\n        Reel18:    \\"ASDMCNEQBOZPLGVJRKYTFUIWXH\\",\n        Reel19:    \\"ATOJYLFXNGWHVCMIRBSEKUPDZQ\\",\n        Reel20:    \\"AUTRZXQLYIOVBPESNHJWMDGFCK\\",\n        Reel21:     \\"AVNKHRGOXEYBFSJMUDQCLZWTIP\\",\n        Reel22:    \\"AWVSFDLIEBHKNRJQZGMXPUCOTY\\",\n        Reel23:    \\"AXKWREVDTUFOYHMLSIQNJCPGBZ\\",\n        Reel24:    \\"AYJPXMVKBQWUGLOSTECHNZFRID\\",\n        Reel25:    \\"AZDNBUHYFWJLVGRCQMPSOEXTKI\\"\n        \n- Encryption Steps:\n    - Initially select the Reel1.\n    - For each character p in the plaintext:\n        - Find character p on the Reel and replace it with the next character on the Reel to get the ciphertext character.\n        - If the current character is at the end of the Reel, go around to the beginning of the Reel.\n        - Move to the next Reel to get the next character. When you reach the last Reel, circle back to the first Reel and continue the encryption process.\n\n **Decryption Rules:**\n\n- Input:\n    - Ciphertext: Uppercase letters string.\n- Output:\n    - Plaintext: Uppercase letters string.\n- Preparation:\n    - Reels (Same as encryption)\n- Decryption Steps (exact opposite of encryption steps):\n    - Initially select the Reel1.\n    - For each character c in the ciphertext:\n        - Find character c on the Reel and replace it with the previous character  on the Reel to get the plaintext character.\n        - If the current character is at the beginning of the Reel, go around to the end of the Reel.\n        - Move to the next Reel to get the next character. When you reach the last Reel, circle back to the first Reel and continue the decryption process.\", \"tag\": \"Classical Cryptography,Polyalphabetic Ciphers\"}
{\"idx\": \"11\", \"title\": \"Custom Four-Square Cipher\", \"rule_content\": \"**Encryption Rules:**\n\n- Input:\n    - Plaintext: Uppercase letters string without punctuation and spaces.\n- Output:\n    - Ciphertext: Uppercase letters string.\n- Preparation:\n    - Four 5x5 Girds\n        - Gird1\n            - K  L  M  N  O\n            P  R  S  T  U\n            V  W  X  Y  Z\n            A  B  C  D  E\n            F  G  H  I  J\n        - Gird2\n            - E  C  H  O  A\n            B  D  F  G  I\n            J  K  L  M  N\n            P  R  S  T  U\n            V  W  X  Y  Z\n        - Gird3\n            - V  O  R  T  E\n            X  A  B  C  D\n            F  G  H  I  J\n            K  L  M  N  P\n            S  U  W  Y  Z\n        - Gird4\n            - K  L  M  N  O\n            P  R  S  T  U\n            V  W  X  Y  Z\n            A  B  C  D  E\n            F  G  H  I  J\n- Encryption Steps:\n    - Cleans up plaintext, removing spaces and non-alphabetic characters, removing the letter Q, and converting all letters to uppercase.\n    - If the plaintext is of odd length, add a letter 'X' to make it of even length.\n    - Split the cleaned plaintext into two-letter groups.\n    - For each double-letter group p1,p2 of the plaintext:\n        - In Gird1 and Gird4, find the position of the first letter and the second letter.\n        - In Gird2 and Gird3, find the letters corresponding to these two positions, use these two letters as the result of encrypting the double letter combination.\n    - Concatenate all the encrypted double letter groups to form the final ciphertext.\n\n **Decryption Rules:**\n\n- Input:\n    - Ciphertext: Uppercase letters string.\n- Output:\n    - Plaintext: Uppercase letters string.\n- Preparation:\n    - Four 5x5 Girds (Same as encryption)\n- Decryption Steps (exact opposite of encryption steps):\n    - Cleans up ciphertext, removing spaces and non-alphabetic characters, and converting all letters to uppercase.\n    - Split the cleaned ciphertext into two-letter groups.\n    - For each double-letter group c1,c2 of the ciphertext:\n        - In Gird2 and Gird3, find the position of the first letter and the second letter.\n        - In Gird1 and Gird4, find the letters corresponding to these two positions, use these two letters as the result of decrypting the double letter combination.\n    - Concatenate all the decrypted double letter groups to form the final plaintext.\", \"tag\": \"Classical Cryptography,Polygraphic Ciphers\"}
{\"idx\": \"12\", \"title\": \"Custom Morbit Cipher\", \"rule_content\": \"**Encryption Rules:**\n\n- Input:\n    - Plaintext: Uppercase letters string without punctuation and spaces.\n- Output:\n    - Ciphertext: A string.\n- Preparation:\n    - Numerical-Index Mapping Table\n        - '..' : 5\n        - '.-' : 4\n        - './' : 9\n        - '-.' : 8\n        - '--' : 6\n        - '-/' : 7\n        - '/.' : 3\n        - '/-' : 1\n        - '//' : 2\n    - morse_code Table\n        - morse_code = {\n                'A': '.-',     'B': '-...',   'C': '-.-.',   'D': '-..',\n                'E': '.',      'F': '..-.',   'G': '--.',    'H': '....',\n                'I': '..',     'J': '.---',   'K': '-.-',    'L': '.-..',\n                'M': '--',     'N': '-.',     'O': '---',    'P': '.--.',\n                'Q': '--.-',   'R': '.-.',    'S': '...',    'T': '-',\n                'U': '..-',    'V': '...-',   'W': '.--',    'X': '-..-',\n                'Y': '-.--',   'Z': '--..',\n            }\n- Encryption Steps:\n    - Convert each character in the plaintext into Morse code according to the morse_code Table, with each character separated by a /, e.g., the Morse code corresponding to AB is '.-/-...'.\n    - Divide Morse code into two pairs of characters. If the length of the Morse code is odd, the last character, without the following mapping, is finally added to the end of the ciphertext.\n    - Each pair of characters is converted into a corresponding numeric string according to the numeric index mapping table.\n    - The encrypted message is represented by a string.\n\n **Decryption Rules:**\n\n- Input:\n    - Ciphertext: A numeric string.\n- Output:\n    - Plaintext: Uppercase letters string.\n- Preparation:\n    - Numerical-Index Mapping Table (Same as encryption)\n    - morse_code Table (Same as encryption)\n- Decryption Steps (exact opposite of encryption steps):\n    - Each digit in the ciphertext is converted to the corresponding character pair according to the digit-index mapping table. If there is a non-numeric character at the end of the ciphertext, it is not processed. By this point, the complete Morse code is obtained.\n    - Obtain the Morse code for each character by splitting the Morse code by /.\n    - Convert the Morse code of each character to the corresponding plaintext character according to the morse_code table.\n    - The final plaintext character is an uppercase string.\", \"tag\": \"Classical Cryptography,Polygraphic Ciphers\"}
{\"idx\": \"13\", \"title\": \"Custom Bifid Cipher\", \"rule_content\": \"**Encryption Rules:**\n\n- Input:\n    - Plaintext: Uppercase letters string without punctuation and spaces.\n- Output:\n    - Ciphertext: Uppercase letters string.\n- Preparation:\n    - 5x5 grid (There is no letter J.Its row and column coordinates are between 0 and 4.):\n        - U  B  I  L  A\n        N  T  C  D  E\n        F  G  H  K  M\n        O  P  Q  R  S\n        V  W  X  Y  Z\n- Encryption Steps:\n    - Remove punctuation, spaces, and the letter J from plaintext.\n    - For each letter p in the plaintext, find its corresponding row and column coordinates (between 0 and 4) in the grid. For example, A is (0,4).\n    - Arrange all row and column coordinates, read all row coordinates first, then read all column coordinates to form a new coordinate sequence. For example, the original has (0,4)(1,2), now read as 0142.\n    - Each time, two numbers are taken out from the new coordinate sequence as new row and column coordinates, and the corresponding letters are found in the grid to form the ciphertext. For example, for 0142, the ciphertext corresponding to (0,1) is B, and the ciphertext corresponding to (4,2) is X. The final ciphertext is BX.\n\n **Decryption Rules:**\n\n- Input:\n    - Ciphertext: Uppercase letters string without punctuation and spaces.\n- Output:\n    - Plaintext: Uppercase letters string without punctuation and spaces.\n- Preparation:\n    - 5x5 grid (Same as encryption)\n- Decryption Steps (exact opposite of encryption steps):\n    - For each letter c in the ciphertext, find its corresponding row and column coordinates (between 0 and 4) in the grid to obtain a sequence of coordinates.\n    - Divide the coordinate sequence into two halves, the first half is all the original row coordinates, the second half is all the original column coordinates, read one from the original row coordinates, read one from the original column coordinates, and find the corresponding letter in the grid according to the original row and column coordinates to form the plaintext.\n        - For example [0,1,4,2], the first half as row coordinates: [0, 1], the second half as column coordinates: [4,2].\n        - Read one from the row coordinates, one from the column coordinates, and so on alternately. Obtain (0,4),(1,2), respectively, and find the corresponding letters in the grid as AC.\", \"tag\": \"Classical Cryptography,Polygraphic Ciphers\"}
{\"idx\": \"14\", \"title\": \"Custom Digrafid Cipher\", \"rule_content\": \"**Encryption Rules:**\n\n- Input:\n    - Plaintext: Uppercase letters string without punctuation and spaces.\n- Output:\n    - Ciphertext: A numeric string without punctuation and spaces.\n- Preparation:\n    - 3 Girds(All row and column numbers are counted from 0.):\n        - Grid 1 (3x9):\n            \n            Q W E R T Y U I O\n            P A S D F G H J K\n            L Z X C V B N M #\n            \n        - Grid 2 (9x3):\n            \n            Q W E\n            R T Y\n            U I O\n            P A S\n            D F G\n            H J K\n            L Z X\n            C V B\n            N M #\n            \n        - Grid 3 (3x3):\n            \n            1 2 3\n            4 5 6\n            7 8 9\n            \n- Encryption Steps:\n    - Remove all spaces and punctuation from the plain text and convert them to capital letters.\n    - Cut the plaintext into groups of 6 characters, and if a group is less than 6 characters long, fill it with `#`.\n    - Split each group of 6 characters into 3 binary groups.\n    - For each binary group `(L1, L2)` do the following:\n        - Determine the row and column numbers  of `L1` in `grid1` as `(l1_row, l1_col)`.\n        - Determine the row and column numbers of `L2` in `grid2` as `(l2_row, l2_col)`.\n        - Find the corresponding number `num3` in `grid3` from `l1_row` and `l2_col`.\n        - Output the triple `(l1_col, num3, l2_row)` of the three numbers.\n            - For example, for the binary (T,H), the row and column numbers of T in `grid1` are (0,4), the row and column numbers of H in `grid2` are (5,0).\n            - Based on `l1_row` (0) and `l2_col`(0) , the corresponding number `num3` found in `grid3` is 1, and the final ternary is (4, 1, 5).\n    - After performing the previous step multiple times and converting all the binary groups to triples, read them in turn to form a string of numbers that can be used as encrypted information. For example (4, 1, 5), (2, 3, 3), (8, 1, 8), the final encrypted message is 415233818.\n\n **Decryption Rules:**\n\n- Input:\n    - Ciphertext: A numeric string without punctuation and spaces.\n- Output:\n    - Plaintext: Uppercase letters string without punctuation and spaces.\n- Preparation:\n    - 3 Girds (Same as encryption)\n- Decryption Steps (exact opposite of encryption steps):\n    - Divide the ciphertext into triples of three numbers.\n    - For each ternary `(x, y, z)` do the following:\n        - Find the row number of y in Gird3 where the value of L1_row is equal to the row number;\n        - Find the column number of y in Gird3, with the value of L2_col equal to that column number;\n        - The value of L1_col is equal to x, the value of L2_row is equal to z.\n        - Find the corresponding letter p1 in Gird1 according to the determined (L1_row,L1_col).\n        - Based on the determined (L2_row,L2_col), find the corresponding letter p2 in Gird2.\n        - p1p2 is the decrypted message of the triad.\n        - For example, for the ternary (4,1,5), in Gird3, the row number corresponding to 1 is 0, so L1_row=0, in Gird3, the column number corresponding to 1 is 0, so L2_col=0. L1_col=4, L2_row=5. According to (0,4) in Gird1, we find the corresponding letter T, and according to (5,0) in Gird2, we decrypt all the ternaries to get the letter p2 p1p2 as the message after decrypting the ternary. We find the corresponding letter H in Gird2 according to (5,0), so the final decryption is TH.\n    - String all the decrypted messages together, remove the `#` at the end (these characters are padding characters added to make the message length a multiple of 6), to form the decrypted plaintext.\", \"tag\": \"Classical Cryptography,Polygraphic Ciphers\"}
{\"idx\": \"15\", \"title\": \"Custom Collon Cipher\", \"rule_content\": \"**Encryption Rules:**\n\n- Input:\n    - Plaintext: Uppercase letters string without punctuation and spaces.\n- Output:\n    - Ciphertext: Uppercase letters string without punctuation and spaces.\n- Preparation:\n    - 5x5 Gird(All row and column numbers are counted from 0.):\n        - M Z S D P\n        K N F L Q\n        G A O X U\n        W R Y V C\n        B T E H I\n        - Located at the first letter of all rows, MKGWB is the row header letter.\n        - Located at the last letter of all columns, BTEHI is the bottom column letter.\n- Encryption Steps:\n    - Remove spaces and punctuation and the letter J from plain text and convert all letters to uppercase.\n    - For each letter p in the plaintext.\n        - Find the position of the letter p in the grid, and then find the corresponding row header and column footer characters accordingly.\n        - Concatenate the row-header and column-bottom characters into a binary as the encrypted message for that letter p.\n        - For example, if the letter p is H, it is in the 4th row, and the row header character is B; it is in the 3rd column, and the column bottom character is H, so the encrypted message is BH.\n    \n    Concatenate all the encrypted messages for the final ciphertext output.\n    \n\n **Decryption Rules:**\n\n- Input:\n    - Ciphertext: Uppercase letters string without punctuation and spaces.\n- Output:\n    - Plaintext: Uppercase letters string without punctuation and spaces.\n- Preparation:\n    - 5x5 Gird (Same as encryption)\n- Decryption Steps (exact opposite of encryption steps):\n    - Take two letters c1,c2 at a time from the ciphertext.\n        - The letter c1 identifies the row position of the decrypted letter p in the grid, find the row where c1 is the row header.\n        - The letter c2 identifies the column position of the decrypted letter p in the grid, and finds the row with c2 at the bottom of the column.\n        - Find the letter at this row and column position in the grid, which is the c1,c2 decrypted message p.\n        - For example, if c1,c2=BH, B is the header of the row is the 4th row, H is the bottom of the row is the 2nd column, (4,2) at the letter H, so BH decrypted to H.\n    - Decrypt the letters in the ciphertext two by two, and output the connected decrypted message as the final plaintext.\", \"tag\": \"Classical Cryptography,Polygraphic Ciphers\"}
{\"idx\": \"16\", \"title\": \"Custom Redefence Figure Cipher\", \"rule_content\": \"**Encryption Rules:**\n\n- Input:\n    - Plaintext: Uppercase letters string without punctuation and spaces.\n- Output:\n    - Ciphertext:  A string without punctuation and spaces.\n- Preparation:\n    - Number of lines: 5\n- Encryption Steps:\n    - Fill in the first plaintext in the first position of the first line.\n    - Two ways to fill:\n        - Downward Fill: Fill the first row with a \\"#\\" (removing the first column, since the first position is already filled with a plaintext letter), then fill the plaintext downwards from the second row to the last row (fifth row).\n        - Upwards: the plaintext is filled upwards from the last line (fifth line) to the second line, and then the first line is filled with a \\"#\\".\n    - For each letter in the plaintext (except the first letter which has been filled in the first position), perform downward padding first, fill one column, then turn to upward padding, then turn to downward padding, and so on alternately, until all the letters have been filled.\n        - For example, HELLOWORLD.The content of the five lines after filling is\n        H L #\n        E R D\n        L O\n        L W\n        O #\n    - Filled out, read line by line, first read the contents of the first line, after reading the contents of each line are added a * sign, marking the end of the line; and then read the contents of the second line, and so on, read all the lines, the formation of the final password text.\n        H L #\n        E R D\n        L O\n        L W\n        O #\n        - Read the final cipher text line by line as \\"HL#*ERD*LO*LW*O#*\\" (i.e., there must be five *'s in the final cipher text to indicate that there are five lines)\n\n **Decryption Rules:**\n\n- Input:\n    - Ciphertext: A string without punctuation and spaces.\n- Output:\n    - Plaintext: Uppercase letters string without punctuation and spaces.\n- Preparation:\n    - Number of lines: 5\n- Decryption Steps (exact opposite of encryption steps):\n    - According to the * in the ciphertext (excluding the * sign), it can be divided into five groups, which are filled into five rows in turn. Get the recovered data in five rows.\n        - For example, like \\"HL#*ERD*LO*LW*O#*\\" ,according to the division of * and then fill in the five lines to get the recovered five lines of data D:\n            H L #\n            E R D\n            L O\n            L W\n            O #\n    - Then read all the columns alternately according to read down first and then read up. Get the uncleared messages.\n        - For example, for the five rows of message D in the previous step, read alternately to get \\"HELLO#WORL#D\\"\n    - Remove the # from the uncleaned message to get the final plaintext.\", \"tag\": \"Classical Cryptography,Transposition Ciphers\"}
{\"idx\": \"17\", \"title\": \"Custom Path Cipher\", \"rule_content\": \"**Encryption Rules:**\n\n- Input:\n    - Plaintext: Uppercase letters string without punctuation and spaces.\n- Output:\n    - Ciphertext:  A string without punctuation and spaces.\n- Preparation:\n    - Maximum number of characters per line: 5\n- Encryption Steps:\n    - Lines are counted from 1.\n    - The plaintext is arranged in a special way: an odd number of lines are written from left to right, and an even number of lines are written from right to left, with a maximum of five letters per line.\n        - For example, for the plaintext \\"LIDAHELLOWORLD\\", first write the first line, from left to right as LIDAH, and then write the second line, from right to left as WOLLE, and then write the third line, from left to right as ORLD, the entire content of the finished writing is expressed as follows\n        LIDAH\n        WOLLE\n        ORLD\n    - Then read by column, each column is read from the top down, each read a column plus a \\"#\\", read out the contents of the final ciphertext.\n        - For example, the above written content is read as LWO#IOR#DLL#ALD#HE# by column.\n\n **Decryption Rules:**\n\n- Input:\n    - Ciphertext: A string without punctuation and spaces.\n- Output:\n    - Plaintext: Uppercase letters string without punctuation and spaces.\n- Preparation:\n    - Number of lines: 5\n- Decryption Steps (exact opposite of encryption steps):\n    - For each character in the ciphertext, it is written from top to bottom; if it encounters #, it switches to the next column and continues writing until the entire ciphertext has been written.\n        - For example, for the ciphertext LWO#IOR#DLL#ALD#HE#,it is written as\n        LIDAH\n        WOLLE\n        ORLD\n    - Then according to the odd-numbered rows from left to right read, the even number of rows from right to left read the order of sequential reading, the final result is the decrypted plaintext.\n        - For example, for the above written content, the first line, read from left to right as LIDAH, the second line, read from right to left as ELLOW, the third line, read from left to right as ORLD, and ultimately the entire content connected, decrypted plaintext as LIDAHELLOWORLD.\", \"tag\": \"Classical Cryptography,Transposition Ciphers\"}
{\"idx\": \"18\", \"title\": \"Custom Rotating Grid Cipher\", \"rule_content\": \"**Encryption Rules:**\n\n- Input:\n    - Plaintext: Uppercase letters string without punctuation and spaces.\n- Output:\n    - Ciphertext:  Uppercase letters  string without punctuation and spaces.\n- Preparation:\n    - Grid and Template:\n        - Prepare a blank grid and a template with holes (fence).\n        - The template used is:\n            \n            ▮  ▮  ▮  ▮\n            ▮  ▮  ▯  ▯\n            ▮  ▮  ▮  ▯\n            ▯  ▮  ▮  ▮\n            \n            Where the white ones are holes, place the template on a blank grid, only through the white holes, and fill in the corresponding positions of the grid with characters.\n            \n- Encryption Steps:\n    - Divide the plaintext into blocks of 16 letters one by one.(If the plaintext is less than 16 long it is one  block)\n        - For example, the plaintext message \\"LOVEHELLOWORLD\\" is less than 16 and is one block.\n    - For each block, perform the following encryption operation:\n        - Place the template with holes on the blank grid.\n        - Fill the grid with the letters of the plaintext message in order through the holes in the template.\n            - For example, the plaintext is \\"LOVEHELLOWORLD\\", through the four holes, after filling in the LOVE grid is\n                \n                [['', '', '', ''],\n                ['', '', 'L', 'O'],\n                ['', '', '', 'V'],\n                ['E', '', '', '']]\n                \n        - The template has a total of four holes, so after filling out the four letters, it can not be filled out, then you need to rotate the template counterclockwise 90 degrees.\n            - For example, after filling in LOVE after rotating the template after the template for:\n                \n                ▮  ▯  ▯  ▮\n                ▮  ▯  ▮  ▮\n                ▮  ▮  ▮  ▮\n                ▮  ▮  ▮  ▯\n                \n        - Repeat filling the visible holes in the grid with the next letter of the plaintext message and rotating the template until the entire grid is completely filled. This will perform 4 fills + rotations and eventually the template will turn to the original template. If the message is not enough to fill the entire grid, it is made up with filler characters (e.g. '#').\n            - For example, if the plain text is \\"LOVEHELLOWORLD\\", after several fills and rotations, the final grid will be\n                \n                [['L', 'H', 'E', 'O'],\n                ['W', 'L', 'L', 'O'],\n                ['O', 'R', 'D', 'V'],\n                ['E', '#', '#', 'L']]\n                \n        - Once the grid is filled, read the contents of the grid line by line as the encrypted message for that block.\n        - When moving on to the next block, empty the contents of the grid and redo the entire fill and rotate operation.\n        \n        Finally, the encrypted messages of all the blocks are connected together to be the final ciphertext.\n        \n\n **Decryption Rules:**\n\n- Input:\n    - Ciphertext: Uppercase letters  string without punctuation and spaces.\n- Output:\n    - Plaintext: Uppercase letters string without punctuation and spaces.\n- Preparation:\n    - Grid and Template (Same as encryption)\n- Decryption Steps (exact opposite of encryption steps):\n    - Divide the ciphertext into blocks of 16 letters one by one.\n    - For each block, perform the following operations:\n        - Write the 16 letters row by row to fill the grid.\n        - Place the template with holes on the filled grid.\n        - Read the letters visible through the holes to get a portion of the plaintext message.\n        - Since there are only four holes, at this point you need to rotate the template 90 degrees counterclockwise to read the next set of letters.\n        - Repeat the reading step four times to get this fast decrypted message.\n    - Connecting the decrypted messages of all the blocks gives the final plaintext.\", \"tag\": \"Classical Cryptography,Transposition Ciphers\"}
{\"idx\": \"19\", \"title\": \"Custom ADFGVX Cipher\", \"rule_content\": \"**Encryption Rules:**\n\n- Input:\n    - Plaintext: Uppercase letters string without punctuation and spaces.\n- Output:\n    - Ciphertext:  Uppercase letters  string without punctuation and spaces.\n- Preparation:\n    - 6x6 Matrix (The rows and columns in the matrix are counted from 0.)\n        \n        [['R', 'U', 'A', '0', 'Q', 'B'], \n        ['D', '2', 'W', 'K', 'S', '1'], \n        ['H', '4', '5', 'F', 'T', 'Z'],\n        ['Y', 'C', 'G', 'X', '7', 'L'], \n        ['9', '8', 'I', '3', 'P', 'N'],\n        ['6', 'J', 'V', 'O', 'E', 'M']]\n        \n    - Encrypted Character Set\n        - \\"ADFGVX\\"\n- Encryption Steps:\n    - For each character in the plaintext:\n        - Find the number of rows and columns of that character in the 6X6 matrix. For example, A has 0 rows and 2 columns.\n        - The position of each character in the encrypted character set is flagged as 0-6. Use the character at the corresponding position in the encrypted character set to replace the number of rows and columns to get the encrypted binary.\n            - For example, the number of rows of A is 0, which corresponds to A in the encrypted character set, and the number of columns of A is 2, which corresponds to F in the encrypted character set. so the encrypted binary corresponding to A is (A,F).The encrypted binary is (A,F).\n        - Read all rows of the encrypted binary, and then read all columns of the encrypted binary to get the final ciphertext.\n            - For example, the encrypted binary is (A,F)(X,V), the last read is AXFV, so the final ciphertext is AXFV.\n\n **Decryption Rules:**\n\n- Input:\n    - Ciphertext: Uppercase letters  string without punctuation and spaces.\n- Output:\n    - Plaintext: Uppercase letters string without punctuation and spaces.\n- Preparation:\n    - 6x6 Matrix (Same as encryption)\n    - Encrypted Character Set (Same as encryption)\n- Decryption Steps:\n    - Divide the ciphertext into two halves.\n    - Take one letter from the upper half and one letter from the lower half each time as a decryption binary:\n        - The position of each character in the encrypted character set is flagged as 0-6, and the position of the corresponding character in the encrypted character set is used to decrypt the number of rows and columns represented by the decrypted binary.\n            - For example, the decrypted binary is the encrypted binary as (A,F), the position of A is 0 and the position of F is 2, so the number of rows is 0 and the number of columns is 2, obtaining (0, 2).\n        - Use the number of rows and columns obtained to find the letter in the corresponding position in the 6x6 matrix as the character after decryption.\n            - For example, the character at (0, 2) is A, and the character after AF decryption is A.\n    - Concatenate all the decrypted characters to get the final plaintext.\", \"tag\": \"Classical Cryptography,Transposition Ciphers\"}
{\"idx\": \"20\", \"title\": \"Custom Transposition Cipher\", \"rule_content\": \"**Encryption Rules:**\n\n- Input:\n    - Plaintext: Uppercase letters string without punctuation and spaces.\n- Output:\n    - Ciphertext:  A string without punctuation and spaces.\n- Preparation:\n    - Transposed sequence list:\n        - [1, 4, 0, 6, 5, 2, 3]\n        - The transposed sequence  list is used to write the plaintext in order one line at a time, and then the columns are adjusted according to the transposed sequence table so that the characters in each line are arranged in the given order.\n        - Columns count from 0.\n- Encryption Steps:\n    - The [1, 4, 0, 6, 5, 2, 3] transposed sequence table has a total of 7 bits, indicating that 7 letters should be written on a line.\n    - Write the plaintext in order, line by line, 7 per line. When there are less than 7, the last line is filled with $. A written grid can be obtained.\n    - According to the transposed sequence table, adjust the order of the columns, that is, the order of the columns is now [the original column 1, the original column 4, the original column 0, the original column 6, the original column 5, the original column 2, the original column 3], you can get after the adjustment of the columns after the order of the grid.\n    - Read the grid row by row and connect them to get the final ciphertext.(Note that $ needs to be retained.)\n\n **Decryption Rules:**\n\n- Input:\n    - Ciphertext: A string without punctuation and spaces.\n- Output:\n    - Plaintext: Uppercase letters string without punctuation and spaces.\n- Preparation:\n    - Transposed sequence list (Same as encryption)\n- Decryption Steps:\n    - Write the ciphertext sequentially, line by line, 7 letters per line.\n    - Read line by line, but when reading each line, read a character in column 2 corresponding to 0, then a character in column 0 corresponding to 1, then a character in column 6 corresponding to 2, etc., etc., etc., etc., etc., etc.\n    - Eventually read the message line by line, remove the $ at the end, you can get the decrypted plaintext.\", \"tag\": \"Classical Cryptography,Transposition Ciphers\"}
{\"idx\": \"21\", \"title\": \"Custom XOR Cipher\", \"rule_content\": \"**Encryption Rules**\n\n- Input:\n    - Plaintext: A string of uppercase letters (A-Z) without punctuation and spaces.\n- Output:\n    - Ciphertext: A binary string containing only 0s and 1s.\n- Preparation:\n    - Fixed Key: A binary string of length 8 (e.g., '10101010').\n    - Permutation Table:\n        - Permutation Table: (2, 0, 3, 1, 4, 6, 5, 7)\n        - Inverse Permutation Table: (1, 3, 0, 2, 4, 6, 5, 7)\n- Encryption Steps:\n    1. Convert Each Character to Binary:\n        - For each character in the plaintext, convert it to its ASCII value.\n        - Convert this ASCII value to an 8-bit binary string.\n    2. XOR Operation:\n        - Perform an XOR operation between the 8-bit binary representation of the character and the fixed key.\n        - Ensure the key is repeated to match the length of the binary representation if needed.\n    3. Permutation:\n        - Apply the permutation table to the XOR result to get the final encrypted binary string for each character.\n    4. Combine Binary Strings:\n        - Concatenate the binary strings of all characters to form the final ciphertext.\n\n**Decryption Rules**\n\n- Input:\n    - Ciphertext: A binary string containing only 0s and 1s.\n- Output:\n    - Plaintext: A string of uppercase letters (A-Z) without punctuation and spaces.\n- Preparation:\n    - Fixed Key: Same binary string of length 8 used for encryption (e.g., '10101010').\n    - Permutation Table:\n        - Permutation Table: (2, 0, 3, 1, 4, 6, 5, 7)\n        - Inverse Permutation Table: (1, 3, 0, 2, 4, 6, 5, 7)\n- Decryption Steps:\n    1. Split Ciphertext into Chunks:\n        - Split the binary ciphertext into 8-bit chunks, each representing an encrypted character.\n    2. Inverse Permutation:\n        - Apply the inverse permutation table to each 8-bit chunk to reverse the permutation applied during encryption.\n    3. XOR Operation:\n        - Perform an XOR operation between the permuted binary chunk and the fixed key.\n    4. Convert Binary to Character:\n        - Convert the resulting binary string back to its decimal equivalent.\n        - Convert this decimal value to its corresponding ASCII character.\n    5. Combine Characters:\n        - Concatenate the characters obtained from each binary chunk to form the final plaintext.\", \"tag\": \"Modern Cryptography,Symmetric Ciphers\"}
{\"idx\": \"22\", \"title\": \"Custom S-BOX Cipher\", \"rule_content\": \"**Encryption Rules:**\n\n- Input:\n    - Plaintext: A string of uppercase letters and spaces.\n- Output:\n    - Ciphertext: A hexadecimal string representing the encrypted data (where A-E needs to be capitalised).\n- Preparation:\n    - Fixed key\n        - KEY = b'1234567890ABCDEF'\n    - S_BOX\n        - S_BOX = {\n        0x00: 0x0F, 0x01: 0x0A, 0x02: 0x07, 0x03: 0x05,\n        0x04: 0x09, 0x05: 0x03, 0x06: 0x0D, 0x07: 0x00,\n        0x08: 0x0E, 0x09: 0x08, 0x0A: 0x04, 0x0B: 0x06,\n        0x0C: 0x01, 0x0D: 0x02, 0x0E: 0x0B, 0x0F: 0x0C\n        }\n- Encryption Steps:\n    1. Padding: If the plaintext is not a multiple of 8 bytes, pad it with \\x00 (null character) to make its length a multiple of 8 bytes.\n    2. Block Splitting: Divide the padded plaintext into 8-byte blocks.\n    3. Block Encryption:\n        - Convert Block to Bytes: Convert each block to bytes using ASCII encoding.\n        - XOR with Key: Apply XOR between the byte block and the fixed key.\n        - Substitute:  Use the S_BOX Replacement Box to replace the high 4 bits and low 4 bits in each byte before stitching them together.\n        - Permute: Perform a simple permutation by rotating each byte left by 1 bit.\n        - XOR with Key: Apply XOR between the permuted byte block and the fixed key again.\n    4. Hexadecimal Encoding: Convert the encrypted byte blocks to a hexadecimal string.\n    5. Concatenate: Concatenate all the hexadecimal strings of the encrypted blocks to form the final ciphertext.\n\n**Decryption Rules:**\n\n- Input:\n    - Ciphertext: A hexadecimal string representing the encrypted data (where A-E needs to be capitalised).\n- Output:\n    - Plaintext: A string of uppercase letters and spaces.\n- Preparation:\n    - Fixed key\n        - KEY = b'1234567890ABCDEF'\n    - INV_S_BOX\n        - INV_S_BOX = {\n        0x0F: 0x00, 0x0A: 0x01, 0x07: 0x02, 0x05: 0x03,\n        0x09: 0x04, 0x03: 0x05, 0x0D: 0x06, 0x00: 0x07,\n        0x0E: 0x08, 0x08: 0x09, 0x04: 0x0A, 0x06: 0x0B,\n        0x01: 0x0C, 0x02: 0x0D, 0x0B: 0x0E, 0x0C: 0x0F\n        }\n- Decryption Steps:\n    1. Block Splitting: Divide the ciphertext into 16-character (8-byte) blocks (each block is 8 bytes long).\n    2. Block Decryption:\n        - Convert Hex to Bytes: Convert each block from hexadecimal string to bytes.\n        - XOR with Key: Apply XOR between the byte block and the fixed key.\n        - Inverse Permute: Perform an inverse permutation by rotating each byte right by 1 bit.\n        - Substitute: Use INV_S_BOX to replace the high four and low four bits in a block of bytes and splice them together.\n        - XOR with Key: Apply XOR between the byte block and the fixed key again.\n    3. Convert Bytes to Text: Convert the decrypted byte blocks back to text using ASCII decoding.\n    4. Remove Padding: Remove any padding characters (\\x00) from the end of the decrypted plaintext.\n    5. Concatenate: Concatenate all the decrypted blocks to form the final plaintext.\", \"tag\": \"Modern Cryptography,Symmetric Ciphers\"}
{\"idx\": \"23\", \"title\": \"Custom RSA Cipher\", \"rule_content\": \"**Encryption Rules:**\n\n- Input:\n    - Plaintext: Uppercase letters string without punctuation and spaces.\n- Output:\n    - Ciphertext:  A sequence of numbers separated by ,. For example, \\"y1,y2,…\\".\n- Preparation:\n    - e: 263\n    - n: 299\n- Encryption Steps:\n    - For each letter p in the plaintext:\n        - Get the decimal number x of the value corresponding to the ascii code of p.\n        - Compute x^e mod n as the ciphertext number y for that letter p . Here ^ denotes the multiplication operation.\n    - Finally, concatenate all the y's and separate them with commas for the final ciphertext.\n\n **Decryption Rules:**\n\n- Input:\n    - Ciphertext: A sequence of numbers separated by ,. For example, \\"y1,y2,…\\".\n- Output:\n    - Plaintext: Uppercase letters string without punctuation and spaces.\n- Preparation:\n    - e: 263\n    - n: 299\n- Decryption Steps:\n    - For each number c in the ciphertext:\n        - Calculate z = c^e mod n. Here ^ means multiplication.\n        Based on the decimal number represented by z, use the ascii code to find the corresponding letter as the plaintext letter p.\n    - Finally, concatenate all p's to get the final plaintext.\", \"tag\": \"Modern Cryptography,Asymmetric Ciphers\"}
{\"idx\": \"24\", \"title\": \"Custom ECC Cipher\", \"rule_content\": \"**Encryption Rules:**\n\n- Input:\n    - Plaintext: Uppercase letters string without punctuation and spaces.\n- Output:\n    - Ciphertext:  A sequence of numbers separated by ,. For example, \\"y1,y2,…\\".\n- Preparation:\n    - k_q_x : 12\n- Encryption Steps:\n    - For each letter p in the plaintext:\n        - Get the decimal number x corresponding to the ascii code of p.\n        - Calculate x * k_q_x as the number y of ciphertexts for that letter p.\n    - Finally, concatenate all y's and separate them with commas to get the final ciphertext.\n\n **Decryption Rules:**\n\n- Input:\n    - Ciphertext: A sequence of numbers separated by ,. For example, \\"y1,y2,…\\".\n- Output:\n    - Plaintext: Uppercase letters string without punctuation and spaces.\n- Preparation:\n    - k_q_x : 12\n- Decryption Steps:\n    - For each number c in the ciphertext:\n        - Compute z = c // k_q_x. where // is used in integer division operations to return the integer part of the quotient (i.e., the result of removing the fractional part).\n        - Based on the decimal number represented by z, use ascii to find the corresponding letter as the plaintext letter p.\n    - Finally, concatenate all p's to get the final plaintext.\", \"tag\": \"Modern Cryptography,Asymmetric Ciphers\"}
{\"idx\": \"25\", \"title\": \"Custom SHA Cipher\", \"rule_content\": \"**Encryption Rules:**\n\n- Input:\n    - Plaintext: Uppercase letters string without punctuation and spaces.\n- Output:\n    - Ciphertext:  Hexadecimal string (and letters a-e in lower case).\n- Preparation:\n    - Key(SHA hash value)\n        - Performing SHA-256 on \\"SECRET_KEY\\" results in '73ef2a4edd7a7fbf07fd5f6faf99674dc0c25a025fd74c221f4c35849e5c0fb3'.\n- Encryption Steps:\n    - Converts a plaintext string into a sequence of bytes (ASCII encoding).\n    - Each byte is encrypted with the corresponding byte of the key using a bitwise different-or (XOR) operation. Repeatedly recycle the key so that the key length is the same as the number of plaintext bytes.\n    - The encrypted byte sequence is converted to a hexadecimal string for ciphertext output.\n\n **Decryption Rules:**\n\n- Input:\n    - Ciphertext: Hexadecimal string (and letters a-e in lower case).\n- Output:\n    - Plaintext: Uppercase letters string without punctuation and spaces.\n- Preparation:\n    - Key (Same as encryption,is a hashed hash obtained by SHA_256)\n- Decryption Steps:\n    - Converts the ciphertext string into a sequence of bytes.\n    - Each byte is decrypted (the decryption process is the same as the encryption process) with the corresponding byte of the key using a bitwise different-or (XOR) operation.\n    - The decrypted byte sequence is converted to a plaintext string.\", \"tag\": \"Modern Cryptography,Hash Function Ciphers \"}
```
Example questions are as follows:

<example 0>
Plaintext: \"O\"

Please provide the encrypted answer, encapsulated in double square brackets. For example, the format should be: [[encrypted answer]].
</example 0>

<example 1>
Ciphertext: \"V\"

Please provide the decrypted answer, encapsulated in double square brackets. For example, the format should be: [[decrypted answer]].
</example 1>

<example 2>
Plaintext: \"B\"

Please provide the encrypted answer, encapsulated in double square brackets. For example, the format should be: [[encrypted answer]].
</example 2>

<example 3>
Ciphertext: \"A\"

Please provide the decrypted answer, encapsulated in double square brackets. For example, the format should be: [[decrypted answer]].
</example 3>

<example 4>
Plaintext: \"S\"

Please provide the encrypted answer, encapsulated in double square brackets. For example, the format should be: [[encrypted answer]].
</example 4>

<example 5>
Ciphertext: \"S\"

Please provide the decrypted answer, encapsulated in double square brackets. For example, the format should be: [[decrypted answer]].
</example 5>

<example 6>
Plaintext: \"HV\"

Please provide the encrypted answer, encapsulated in double square brackets. For example, the format should be: [[encrypted answer]].
</example 6>

<example 7>
Ciphertext: \"ZP\"

Please provide the decrypted answer, encapsulated in double square brackets. For example, the format should be: [[decrypted answer]].
</example 7>

<example 8>
Plaintext: \"TNKGPHLSYPV\"

Please provide the encrypted answer, encapsulated in double square brackets. For example, the format should be: [[encrypted answer]].
</example 8>

<example 9>
Ciphertext: \"VJYWRDAOPHZ\"

Please provide the decrypted answer, encapsulated in double square brackets. For example, the format should be: [[decrypted answer]].
</example 9>


请完成上述谜题的训练场环境类实现，包括所有必要的方法。
"""

from bootcamp import Basebootcamp
import random
from bootcamp import Basebootcamp

class KorCipherCustomInverseShiftSubstitutionCipherbootcamp(Basebootcamp):
    def __init__(self, **params):
        super().__init__(**params)
        self.standard_alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
        self.reversed_alphabet = "ZYXWVUTSRQPONMLKJIHGFEDCBA"
        self.substitution_alphabet = "RFDJUHABCEGIKLMNOPQSTVWXYZ"
    
    def _encrypt_single(self, char):
        """实现加密三步骤的原子操作"""
        # 步骤1：反向映射
        reversed_char = self.reversed_alphabet[self.standard_alphabet.index(char)]
        # 步骤2：前移4位（考虑循环）
        shifted_index = (self.standard_alphabet.index(reversed_char) + 4) % 26
        # 步骤3：替换表转换
        return self.substitution_alphabet[shifted_index]

    def _decrypt_single(self, char):
        """实现解密三步骤的原子操作"""
        # 逆步骤3：查找替换表位置
        sub_index = self.substitution_alphabet.index(char)
        # 逆步骤2：后移4位（考虑循环）
        unshifted_char = self.standard_alphabet[(sub_index - 4) % 26]
        # 逆步骤1：反向映射还原
        return self.standard_alphabet[self.reversed_alphabet.index(unshifted_char)]

    def case_generator(self):
        """生成合法问题实例，保证可验证性"""
        # 生成随机长度3-8的明文
        plaintext = ''.join(random.choices(self.standard_alphabet, k=random.randint(3, 8)))
        ciphertext = ''.join([self._encrypt_single(c) for c in plaintext])
        # 随机生成加密或解密问题
        if random.random() < 0.5:
            return {
                'type': 'encrypt',
                'question': plaintext,
                'answer': ciphertext
            }
        else:
            return {
                'type': 'decrypt',
                'question': ciphertext,
                'answer': plaintext
            }
    
    @staticmethod
    def prompt_func(question_case):
        """动态生成问题描述"""
        if question_case['type'] == 'encrypt':
            return (
                "请加密以下明文，加密规则：\n"
                "1. 反向字母表替换（A→Z，B→Y）\n"
                "2. 前移4位（Z→D）\n"
                "3. 最终替换表：RFDJUHABCEGIKLMNOPQSTVWXYZ\n\n"
                f"明文：{question_case['question']}\n"
                "答案格式：[[大写字母串]] 例如：[[ABC]]"
            )
        else:
            return (
                "请解密密文，解密规则：\n"
                "1. 查找替换表位置\n"
                "2. 后移4位还原\n"
                "3. 逆向反向映射\n\n"
                f"密文：{question_case['question']}\n"
                "答案格式：[[大写字母串]] 例如：[[XYZ]]"
            )
    
    @staticmethod
    def extract_output(text):
        """增强型答案提取"""
        import re
        # 匹配最后一个出现的[[...]]结构
        matches = re.findall(r'\[\[([A-Z]+)\]\]', text)
        return matches[-1] if matches else None
    
    @classmethod
    def _verify_correction(cls, solution, identity):
        """通用验证逻辑"""
        return solution == identity['answer']

# 验证测试
if __name__ == "__main__":
    # 单元测试加密正确性
    cipher = KorCipherCustomInverseShiftSubstitutionCipherbootcamp()
    assert cipher._encrypt_single('A') == 'J'  # A→Z→D→J
    assert cipher._decrypt_single('J') == 'A'  # J→D→Z→A
    
    # 测试完整流程
    test_case = cipher.case_generator()
    print(f"Generated Case: {test_case}")
    prompt = cipher.prompt_func(test_case)
    print(f"Prompt:\n{prompt}")
    
    # 模拟LLM回答
    simulated_answer = f"[[{test_case['answer']}]]"
    print(f"Simulated Answer: {simulated_answer}")
    print(f"Verification Result: {cipher.verify_score(simulated_answer, test_case)}")
